package com.tsystems.tuni.sportplanet.dao;

import javax.persistence.Query;

import com.tsystems.tuni.sportplanet.entity.Company;
import com.tsystems.tuni.sportplanet.entity.Department;
import com.tsystems.tuni.sportplanet.entity.Team;

/**
 * 
 * @author Yuriy Eremin
 * 
 */
public class CompanyDAOImpl extends GenericDAOImpl<Company> implements
		CompanyDAO {

	public CompanyDAOImpl() {
		super();
	}

	@Override
	public Company getCompanyByTeam(Team team) {
		Query query = em
				.createQuery("select t.company from Team t where t=:team");
		query.setParameter("team", team);
		return (Company) query.getSingleResult();
	}

	@Override
	public String getCompanyContact(String company) {
		String q = "select d from Department d where d.company.companyName=:company";
		Query query = em.createQuery(q);
		query.setParameter("company", company);
		Department dep = (Department) query.getSingleResult();
		return dep.getLocation().getCity() + ", email: "
				+ dep.getCompany().getEmail();
	}
}
